{$CLEO .qa}
{$USE CLEO+}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "GrbgMns"

// By ArtemQa146

const
    Trash_car = 0@
    Garbage_Man_1 = 31@
    Garbage_Man_2 = 30@
    Driver_Man = 29@
    Procces = 28@
    Object_A = 27@
    Render_Obj = 26@
    Render_Stop = 25@
    Project_props = 24@
    Dump = 23@
    Dump_check = 22@
    Time_Start = 5 //    
    Time_End = 11 //      .       
    Speed_Stop = 5.0 //     ,         ,         .
    Time_Stop = 20000 //    .   ,  -   ,  -5   .
    Time_Stop_props = 10000
    End_Pause = 25000 // ,       
end

0085: 24@ = 0@ // (int)
0085: 20@ = 1@ // (int)
0085: 19@ = 2@ // (int)
0085: 18@ = 3@ // (int)
0085: 17@ = 4@ // (int)

12@ = false

while true
wait 100
if
    Player.Defined(0)
then

    //  ,     
    wait 50
    13@ = 0
    while 0EA8: get_any_car_no_save_recursive 13@ progress_to 13@ car_to Trash_car
    046C: 1@ = car Trash_car driver
    0E12: get_vehicle Trash_car subclass_to 3@
    if and
        3@ == 0
        not 1@ == -1
        not is_car_script_controlled Trash_car
        82CA:   not car Trash_car bounding_sphere_visible
        not locate_char_distance_to_car $Player_actor car Trash_car radius 50.0
        locate_char_distance_to_car $Player_actor car Trash_car radius 150.0
    then
        089F: get_actor 1@ pedtype_to 3@
        if or
            3@ == 4
            3@ == 5
        then
            009B: destroy_actor 1@
            06BE: 4@ = car Trash_car y_angle
            0174: 5@ = car Trash_car Z_angle
            00AA: store_car Trash_car position_to 1@ 2@ 3@
            00A6: destroy_car Trash_car
            
            repeat
            wait 0
            04ED: load_animation  "PedEventsMod"
            until 04EE:   animation "PedEventsMod" loaded
            
            repeat
            wait 0
            model.Load(408)
            until model.Available(408)

        //      
        model.Load(18@) //   
        model.Load(19@) //   
        model.Load(20@) //   
        if
            not model.Available(18@)
        then
            repeat
            wait 0
            model.Load(18@)
            until model.Available(18@)
        end
        if
            not model.Available(19@)
        then
            repeat
            wait 0
            model.Load(19@)
            until model.Available(19@)
        end
        if
            not model.Available(20@)
        then
            repeat
            wait 0
            model.Load(20@)
            until model.Available(20@)
        end
        038B: load_requested_models
        00A5: Trash_car = create_car 408 at 1@ 2@ 3@
        0731: set_car Trash_car y_angle_to 4@
        0175: set_car Trash_car Z_angle_to 5@
        00AE: set_car Trash_car traffic_behaviour_to 0
        00AD: set_car Trash_car max_speed_to 15.0
        0129: Driver_Man = create_actor_pedtype 4 model 18@ in_car Trash_car driverseat
        009A: Garbage_Man_1 = create_actor_pedtype 4 model 19@ at 0.0 0.0 0.0
        009A: Garbage_Man_2 = create_actor_pedtype 4 model 20@ at 0.0 0.0 0.0
        060A: create_decision_maker_type 0 store_to 1@ // decision\allowed\m_.ped files
        060B: set_actor Garbage_Man_1 decision_maker_to 1@
        060B: set_actor Garbage_Man_2 decision_maker_to 1@
        model.Destroy(408) // 
        model.Destroy(18@) //   
        model.Destroy(19@) //   
        model.Destroy(20@) //   
        0F02: create_render_object_to_char_bone_from_special Garbage_Man_2 special_model 17@ bone 34 offset 0 0 0 rotation 0 0 0 store_to Render_Stop
        0E37: set_render_object_scale Render_Stop 1.2 1.2 1.2
        020A: set_car Trash_car door_status_to 2
        
        0E24: fix_char Garbage_Man_1 ground 0 brightness 1 and_fade_in 0
        0E24: fix_char Garbage_Man_2 ground 0 brightness 1 and_fade_in 0
        
        0812: AS_actor Garbage_Man_1 perform_animation "OnTruck" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1  // versionB
        0812: AS_actor Garbage_Man_2 perform_animation "OnTruck" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1  // versionB

        //     
        05D2: AS_actor Driver_Man run_to_and_hijack_car Trash_car max_search_radius 10.0 traffic_behavior 0
        
            //  
            11@ = false
            timera = 0
            Procces = -1
            12@ = false
            
            //  
            repeat
            wait 0
                // ,       -
                if and
                    056D:   actor Garbage_Man_1 defined
                    056D:   actor Garbage_Man_2 defined
                    056D:   actor Driver_Man defined
                    056E:   car Trash_car defined
                then
                
                    //        
                    046C: 1@ = car Trash_car driver
                    if or
                        1@ == -1 //  
                        0119:   car Trash_car wrecked
                        not locate_char_distance_to_car $Player_actor car Trash_car radius 200.0
                        80DB:   not actor Driver_Man in_car Trash_car
                    then
                        break
                    end
                    
                    //        
                    080E: get_actor Driver_Man ped_event_to 1@
                    080E: get_actor Garbage_Man_1 ped_event_to 2@
                    080E: get_actor Garbage_Man_2 ped_event_to 3@
                    if or
                        1@ == 9 //   
                        2@ == 9
                        3@ == 9
                        0118:   actor Driver_Man dead
                        0118:   actor Garbage_Man_1 dead
                        0118:   actor Garbage_Man_2 dead
                    then
                        break
                    end

                        //           .   ,    .
                        if
                            11@ == false
                        then
                            0A97: 1@ = car Trash_car struct
                            0A8E: 2@ = 1@ + 0x18
                            0A8D: 2@ = read_memory 2@ size 4 virtual_protect 0
                            0AA7: call_function 0x4C5400 num_params 2 pop 2 "turnl_rr_prmFF9900024" 2@ 3@
                            0AA7: call_function 0x4C5400 num_params 2 pop 2 "turnl_lr_prmFF9900024" 2@ 4@
                            if and
                                3@ <> 0 // "turnl_rr_prmFF9900024"
                                4@ <> 0 // "turnl_lr_prmFF9900024"
                            then
                                gosub @Ped_attach_to_car
                            else
                                0AA7: call_function 0x4C5400 num_params 2 pop 2 "wing_rf_dummy" 2@ 3@
                                0AA7: call_function 0x4C5400 num_params 2 pop 2 "wing_lf_dummy" 2@ 4@
                                if and
                                    3@ <> 0 // "wing_rf_dummy"
                                    4@ <> 0 // "wing_lf_dummy"
                                then
                                    gosub @Ped_attach_to_car
                                else
                                    break
                                end
                            end
                        end
                                        //       
                                    
                                //  
                                if and
                                    Project_props == 0
                                    Procces == 0
                                    timera > Time_Stop
                                then
                                    gosub @Zone //    
                                    gosub @Traffic_Light //     ,      
                                    timera -= 5000
                                    02E3: 1@ = car Trash_car speed
                                    if and
                                        14@ == true // @Traffic_Light
                                        12@ == true // @Zone
                                        1@ > Speed_Stop
                                    then
                                        14@ = false
                                        12@ = false
                                        02D4: car Trash_car turn_off_engine
                                        7@ = -4.0
                                        Procces = 1
                                    end
                                end

                                //   Project_props
                                if and
                                    timera > Time_Stop_props
                                    Project_props == 1
                                    Procces == 0
                                then
                                    gosub @Dump
                                    02E3: 1@ = car Trash_car speed
                                    if and
                                        Dump_check == true
                                        1@ > Speed_Stop
                                    then
                                        14@ = false
                                        12@ = false
                                        02D4: car Trash_car turn_off_engine
                                        7@ = -4.0
                                        Procces = 1
                                    end
                                end

                                //  ,      
                                if
                                    Procces == 1
                                then
                                    02E3: 1@ = car Trash_car speed
                                    if
                                        1@ < 0.1
                                    then
                                        timera = 0
                                        0441: 5@ = car Trash_car model
                                        07E4: get_model 5@ dimensions_cornerA_to 1@ 7@ 3@ dimensions_cornerB_to 4@ 4@ 4@ // B
                                        7@ -= 1.0
                                        Procces = 2
                                        timerb = 0
                                    end
                                end
                                
                                //    
                                if
                                    Procces > 2
                                then
                                    04BA: set_car Trash_car speed_to 0.0
                                        if
                                            timerb < 500
                                        then
                                            //   ,  
                                            0E5B: get_car_dummy_coord Trash_car dummy 1 world_coords 1 invert_x 1 store_to 1@ 2@ 3@
                                            024F: create_corona_with_radius 0.3 type 4 lensflares 0 with_color 255 160 0 at 1@ 2@ 3@
                                            0E5B: get_car_dummy_coord Trash_car dummy 1 world_coords 1 invert_x 0 store_to 1@ 2@ 3@
                                            024F: create_corona_with_radius 0.3 type 4 lensflares 0 with_color 255 160 0 at 1@ 2@ 3@
                                        else
                                            if
                                                timerb > 1000
                                            then
                                                timerb = 0
                                            end
                                        end
                                end

                                //     
                                if and
                                    Project_props == 0
                                    Procces == 2
                                then
                                    0441: 5@ = car Trash_car model
                                    07E4: get_model 5@ dimensions_cornerA_to 1@ 7@ 3@ dimensions_cornerB_to 4@ 4@ 4@ // B
                                    7@ -= 1.0
                                    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 0.5 7@ 0.0
                                    
                                    02C0: store_to 21@ 22@ 6@ ped_path_coords_closest_to 1@ 2@ 3@
                                    02C0: store_to 4@ 5@ 6@ ped_path_coords_closest_to 1@ 2@ 3@
                                    02C0: store_to 1@ 2@ 3@ ped_path_coords_closest_to 1@ 2@ 3@
                                    4@ += 2.0
                                    5@ += 2.0
                                    21@ -= 2.0
                                    22@ -= 2.0
                                        //               ,    
                                        if and
                                            06BD:   no_obstacles_between 21@ 22@ 3@ and 4@ 5@ 6@ solid 1 car 1 actor 1 object 1 particle 0
                                            0EEB: locate_car_distance_to_coordinates Trash_car pos 1@ 2@ 3@ radius 13.0
                                        then
                                        else
                                            0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 5.0 7@ 0.0
                                        end
                                    model.Load(1264)
                                    038B: load_requested_models
                                    0E01: create_object_no_save 1264 at 1@ 2@ 3@ offset 0 ground 1 to Object_A
                                    model.Destroy(1264)
                                    0382: set_object Object_A collision_detection 0
                                    0465: remove_actor Garbage_Man_1 from_turret_mode
                                    0E24: fix_char Garbage_Man_1 ground 1 brightness 1 and_fade_in 0
                                    0812: AS_actor Garbage_Man_2 perform_animation "OnTruck_Stop" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1
                                    Procces = 3
                                end
                                
                                //      Project_props
                                if and
                                    Project_props == 1
                                    Procces == 2
                                then
                                    0441: 5@ = car Trash_car model
                                    07E4: get_model 5@ dimensions_cornerA_to 1@ 7@ 3@ dimensions_cornerB_to 4@ 4@ 4@ // B
                                    7@ -= 1.0
                                    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 0.5 7@ 0.0
                                    0465: remove_actor Garbage_Man_1 from_turret_mode
                                    0E24: fix_char Garbage_Man_1 ground 1 brightness 1 and_fade_in 0
                                    0812: AS_actor Garbage_Man_2 perform_animation "OnTruck_Stop" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1
                                    Procces = 3
                                end
                                
                                //   
                                if
                                    Procces == 3
                                then
                                    if
                                        Project_props == 0
                                    then
                                        0400: store_coords_to 1@ 2@ 3@ from_object Object_A with_offset 0.0 0.0 0.0
                                    else
                                        if
                                            03CA:   object dump exists
                                        then
                                            0400: store_coords_to 1@ 2@ 3@ from_object dump with_offset 0.0 0.0 0.0
                                        else
                                            procces = 5
                                        end
                                    end
                                    04C4: store_coords_to 4@ 5@ 6@ from_actor Garbage_Man_1 with_offset 0.0 0.0 0.0
                                    0E27: get_angle_from_two_coords 1@ 2@ and 4@ 5@ to 6@ //     
                                    07CD: AS_actor Garbage_Man_1 walk_to 1@ 2@ 3@ stop_with_angle 6@ within_radius 0.0
                                    Procces = 4
                                    timera = 0
                                end
                                
                                //  
                                if and
                                    Project_props == 0
                                    Procces == 4
                                then
                                    0400: store_coords_to 1@ 2@ 3@ from_object Object_A with_offset 0.0 0.0 0.0
                                        if or
                                            timera > 20000
                                            00EC:   actor Garbage_Man_1 sphere 0 near_point 1@ 2@ radius 0.5 0.5
                                        then
                                            0812: AS_actor Garbage_Man_1 perform_animation "PickUpTrash" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                                            Procces = 5
                                            timera = 0
                                        end
                                    end
                                    
                                //   Project_props
                                if and
                                    Project_props == 1
                                    Procces == 4
                                then
                                    if
                                        03CA:   object dump exists
                                    then
                                    0400: store_coords_to 1@ 2@ 3@ from_object dump with_offset 0.0 0.0 0.0
                                        if or
                                            timera > 20000
                                            00EC:   actor Garbage_Man_1 sphere 0 near_point 1@ 2@ radius 2.0 2.0
                                        then
                                            0812: AS_actor Garbage_Man_1 perform_animation "PickUpTrash" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                                            Procces = 5
                                            timera = 0
                                        end
                                    else
                                        0812: AS_actor Garbage_Man_1 perform_animation "PickUpTrash" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 0 time -1
                                        Procces = 5
                                        timera = 0
                                    end
                                end

                                //    
                                if
                                    Procces == 5
                                then
                                    0613: 1@ = actor Garbage_Man_1 animation "PickUpTrash" time
                                    if or
                                        timera > 2000
                                        1@ > 0.7
                                    then
                                    model.Load(1264)
                                    038B: load_requested_models
                                    0E2E: create_render_object_to_char_bone Garbage_Man_1 model 1264 bone 24 offset 0.3 0.2 0 rotation 0 0 0 store_to Render_Obj
                                    0E37: set_render_object_scale Render_Obj 0.7 0.7 0.7
                                    model.Destroy(1264)
                                    if
                                        Project_props == 0
                                    then
                                        object.Destroy(Object_A)
                                    end
                                    0174: 1@ = car Trash_car Z_angle
                                    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 0.0 7@ 0.0
                                    07CD: AS_actor Garbage_Man_1 walk_to 1@ 2@ 3@ stop_with_angle 1@ within_radius 0.0
                                    Procces = 6
                                    timera = 0
                                    end
                                end
                                
                                //      
                                if
                                    Procces == 6
                                then
                                    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 0.0 7@ 0.0
                                    if or
                                        00EC:   actor Garbage_Man_1 sphere 0 near_point 1@ 2@ radius 0.6 1.0
                                        timera > 20000
                                    then
                                        0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 0.0 7@ 0.0
                                        00A1: put_actor Garbage_Man_1 at 1@ 2@ 3@
                                        0174: 1@ = car Trash_car Z_angle
                                        0173: set_actor Garbage_Man_1 Z_angle_to 1@
                                        0E24: fix_char Garbage_Man_1 ground 1 brightness 1 and_fade_in 0
                                        0812: AS_actor Garbage_Man_1 perform_animation "ThrowTrash" IFP "PedEventsMod" framedelta 4.0 loopA 0 lockX 0 lockY 0 lockF 1 time -1
                                        0E35: set_render_object_position Render_Obj 0 0.4 0 //    ,        
                                        timera = 0
                                        Procces = 7
                                    end
                                end
                                
                                //  
                                if 
                                    Procces == 7
                                then
                                    0613: 1@ = actor Garbage_Man_1 animation "ThrowTrash" time
                                        if
                                            1@ > 0.6
                                        then
                                            0E31: set_render_object_visible Render_Obj 0 //  ,     
                                        end

                                    if
                                        timera > 1500
                                    then
                                    timera = 0
                                    0E2F: delete_render_object Render_Obj
                                    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 1.5 7@ 0.0
                                    0174: 4@ = car Trash_car Z_angle
                                    07CD: AS_actor Garbage_Man_1 walk_to 1@ 2@ 3@ stop_with_angle 4@ within_radius 0.0
                                    Procces = 8
                                    end
                                end

                                //        
                                if 
                                    Procces == 8
                                then
                                    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 1.5 7@ 0.0
                                        if or
                                            00EC:   actor Garbage_Man_1 sphere 0 near_point 1@ 2@ radius 0.6 0.6
                                            timera > 2500
                                        then
                                            11@ = false
                                            0ABF: set_car Trash_car engine_state_to 1 //  
                                            00AE: set_car Trash_car traffic_behaviour_to 0
                                            0687: clear_actor Garbage_Man_1 task //   ,        
                                            0812: AS_actor Garbage_Man_1 perform_animation "OnTruck" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1
                                            0812: AS_actor Garbage_Man_2 perform_animation "OnTruck" IFP "PedEventsMod" framedelta 4.0 loopA 1 lockX 0 lockY 0 lockF 1 time -1
                                            05D2: AS_actor Driver_Man run_to_and_hijack_car Trash_car max_search_radius 10.0 traffic_behavior 0
                                            Procces = -1
                                        end
                                    end
                                else
                            break
                        end
                    until not Player.Defined(0)
            
            //    ,          
            if
                056D:   actor Garbage_Man_1 defined
            then
                0465: remove_actor Garbage_Man_1 from_turret_mode
                01C2: remove_references_to_actor Garbage_Man_1 // Like turning an actor into a random pedestrian
            end
                if
                    056D:   actor Garbage_Man_2 defined
                then
                    0465: remove_actor Garbage_Man_2 from_turret_mode
                    01C2: remove_references_to_actor Garbage_Man_2 // Like turning an actor into a random pedestrian
                end
                    if
                        056D:   actor Driver_Man defined
                    then
                        01C2: remove_references_to_actor Driver_Man // Like turning an actor into a random pedestrian
                    end
                        if
                            056E:   car Trash_car defined
                        then
                            01C3: remove_references_to_car Trash_car
                        end
                            if
                                03CA:   object Object_A exists
                            then
                                01C4: remove_references_to_object Object_A // This object will now disappear when the player looks away
                            end
                        04EF: release_animation "PedEventsMod"
                        wait End_Pause
                        0A93: terminate_this_custom_script
                    end
                end
            end
        end

end



:Zone
0842: 2@ = player $PLAYER_CHAR town_number
0E40: get_current_hour 1@
if and
    $ACTIVE_INTERIOR == 0
    1@ >= Time_Start
    1@ <= Time_End
    not 2@ == 0 //    .  ,      
then
    12@ = true
end
return

:Traffic_Light
14@ = true
13@ = 0
while 0EA9: get_any_object_no_save_recursive 13@ progress_to 13@ object_to 1@
    if or
        09CC:   object 1@ model_is 3855 // GAY_TRAFFIC_LIGHT
        09CC:   object 1@ model_is 1315 // TRAFFICLIGHT1
        09CC:   object 1@ model_is 1352 // CJ_TRAFFIC_LIGHT3
        09CC:   object 1@ model_is 1350 // CJ_TRAFFIC_LIGHT4
        09CC:   object 1@ model_is 1351 // CJ_TRAFFIC_LIGHT5
        09CC:   object 1@ model_is 1284 // MTRAFFIC2
        09CC:   object 1@ model_is 1283 // MTRAFFIC1
    then
        if
            locate_car_distance_to_object Trash_car object 1@ radius 20.0
        then
            14@ = false
            break
            return
        end
    end
end
return

:Dump
Dump_check = false
13@ = 0
while 0EA9: get_any_object_no_save_recursive 13@ progress_to 13@ object_to Dump
if or
    09CC:   object Dump model_is 1328
    09CC:   object Dump model_is 1330
    09CC:   object Dump model_is 1334
    09CC:   object Dump model_is 1331
    09CC:   object Dump model_is 1343
    09CC:   object Dump model_is 1372
    09CC:   object Dump model_is 1227
then
    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 6.0 -6.0 0.0
    if
        0EEC: locate_object_distance_to_coordinates Dump pos 1@ 2@ 3@ radius 6.0
    then
        Dump_check = true
        break
    end
end
if or
    09CC:   object Dump model_is 3035
    09CC:   object Dump model_is 1339
    09CC:   object Dump model_is 1265
    09CC:   object Dump model_is 1440
    09CC:   object Dump model_is 1264
    09CC:   object Dump model_is 1415
then
    0407: store_coords_to 1@ 2@ 3@ from_car Trash_car with_offset 6.0 -6.0 0.0
    if
        0EEC: locate_object_distance_to_coordinates Dump pos 1@ 2@ 3@ radius 6.0
    then
        Dump_check = true
        break
    end
end
end
return


:Ped_attach_to_car
//    
3@ += 0x10
3@ += 0x30
0D4E: 5@ = read_struct 3@ offset 0x0 size 4
0D4E: 6@ = read_struct 3@ offset 0x4 size 4
0D4E: 7@ = read_struct 3@ offset 0x8 size 4
7@ += 0.7
//       
0464: put_actor Garbage_Man_1 into_turret_on_car Trash_car at_car_offset 5@ 6@ 7@ position 0 shooting_angle_limit 0.0 with_weapon 0

//    
4@ += 0x10
4@ += 0x30
0D4E: 8@ = read_struct 4@ offset 0x0 size 4
0D4E: 9@ = read_struct 4@ offset 0x4 size 4
0D4E: 10@ = read_struct 4@ offset 0x8 size 4
10@ += 0.7
0464: put_actor Garbage_Man_2 into_turret_on_car Trash_car at_car_offset 8@ 9@ 10@ position 0 shooting_angle_limit 0.0 with_weapon 0

0E24: fix_char Garbage_Man_1 ground 0 brightness 1 and_fade_in 0
0E24: fix_char Garbage_Man_2 ground 0 brightness 1 and_fade_in 0

11@ = true //     
Procces = 0
return